package com.leetcode.greedy;

/**
 * @author Dennis Li
 * @date 2020/7/23 21:28
 */
public class CheckPossibility_665 {

    public boolean checkPossibility(int[] nums) {
        int count = 0;
        for (int i = 1; i < nums.length && count < 2; i++) {
            if (nums[i] > nums[i + 1]) {
                count++;
                if(i - 2 > 0 && nums[i - 2] > nums[i])
                    nums[i] = nums[i - 1];
                else
                    nums[i - 1] = nums[i];
            }
        }
        return count < 2;
    }

    public boolean check(int[] nums, int start, boolean second) {
        if(second && nums[start] > nums[start + 2]) return false;
        for (int i = start; i < nums.length - 1; i++) {
            // 删除的是第二个
            if(second && i == start + 1) continue;
            if (nums[i] > nums[i + 1]) return false;
        }
        return true;
    }

}
